<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/bootstrap-table.min.css" rel="stylesheet">
<script src="../js/jquery-1.11.3.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/bootstrap-table.min.js"></script>
<script src="../js/bootstrap-table-zh-CN.min.js"></script>
<style type="text/css">
#table-1 thead, #table-1 tr {
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #a8bfde;
}

#table-1 {
	border-bottom-width: 1px;
	border-bottom-style: solid;
	border-bottom-color: #a8bfde;
}
/* Padding and font style */
#table-1 td, #table-1 th {
	padding: 5px 10px;
	font-size: 12px;
	font-family: Verdana;
	color: #5b7da3;
}
/* Alternating background colors */
#table-1 tr:nth-child(even) {
	background: #d3dfed
}

#table-1 tr:nth-child(odd) {
	background: #FFF
}
</style>
</head>
<body>

	<h1 style="color: #409EFF; text-align: center;">欢迎进入家族族谱管理员系统</h1>

	<hr>

		<div align="right">
		<a href="getUser.action">用户管理</a> <a href="findReport.action">审核举报</a>
		<a href="editUser.action">个人资料</a> <a href="${pageContext.request.contextPath}/logout.action">退出系统</a>
	</div>
	<div id="page-wrapper">
		<table align="center" id="table-1">
			<tr>
				<th>用户名称</th>
				<th>密码</th>
				<th>性别</th>
				<th>联系方式</th>
				<th>管理</th>
			</tr>
			<tr>
				<td>${user.username}</td>
				<td>${user.password}</td>
				<td><c:choose>
						<c:when test="${user.sex == 0 }">女</c:when>
						<c:when test="${user.sex == 1 }">男</c:when>
					</c:choose></td>
				<td>${user.iphone}</td>
				<td><a href="#" class="btn btn-primary btn-xs"
					data-toggle="modal" data-target="#usersEditDialog"
					onclick="editusers(${user.user_id})">修改</a></td>
			</tr>
		</table>
	</div>
	<div class="modal fade" id="usersEditDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="edit_users_form">
						<input type="hidden" id="edit_user_id" name="user_id" />
						<div class="form-group">
							<label for="edit_username" class="col-sm-2 control-label">
								用户名 </label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_username"
									placeholder="用户名" name="username" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_password" class="col-sm-2 control-label">密码</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_password"
									placeholder="密码" name="password" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_sex" class="col-sm-2 control-label">用户性别</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_sex"
									placeholder="用户性别" name="sex" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_iphone" class="col-sm-2 control-label">手机号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_iphone"
									placeholder="手机号" name="iphone" />
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal"
						onclick="cleargood()">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="updateusers()">修改用户</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
$("img").click(function(){
    var at=$(this).attr("src")
    $("#touimg").attr("src",at)
})
//清空新建商品分类窗口中的数据
	function clearusers() {
	    $("#new_username").val("");
	    $("#new_password").val("");
	    $("#new_sex").val("");
	    $("#new_iphone").val("");
	    $("#new_ident").val("");
	}
	//清空新建商品分类窗口中的数据
	function cleargood() {
	    $("#edit_username").val("");
	    $("#edit_password").val("");
	    $("#edit_sex").val("");
	    $("#edit_iphone").val("");
	    $("#edit_ident").val("");
	}
	function createusers() {
	$.post("${pageContext.request.contextPath}/create.action",
	$("#new_users_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("管理员用户创建成功！");
	            window.location.reload();
	        }else{
	            alert("管理员用户创建失败！");
	            window.location.reload();
	        }
	    });
	}
	function editusers(user_id) {
		$.post("${pageContext.request.contextPath}/getUserById.action",{"user_id":user_id},function(data){
			 $("#edit_user_id").val(data.user_id);
	         $("#edit_username").val(data.username);
	         $("#edit_password").val(data.password);
	         $("#edit_sex").val(data.sex);
	         $("#edit_iphone").val(data.iphone);	         
	         $("#edit_ident").val(data.ident);
		});
	}
	function updateusers() {
		$.post("${pageContext.request.contextPath}/user/update.action",$("#edit_users_form").serialize(),function(data){
			if(data =="OK"){
				alert("用户信息更新成功！");
				window.location.reload();
			}else{
				alert("用户信息更新失败！");
				window.location.reload();
			}
		});
	}
	function deleteusers(user_id) {
	    if(confirm('确实要删除该用户吗?')) {
	$.post("${pageContext.request.contextPath}/deleteUser.action",{"user_id":user_id},
	function(data){
	            if(data =="OK"){
	                alert("用户删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除用户失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>
</html>
<%@include file="/WEB-INF/footer.jsp"%>
